package com.imy.luascript.base.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import androidx.appcompat.app.AppCompatActivity;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 用于分离业务的View
 * Created by user on 2017/2/14.
 */

public abstract class BaseCustomViewGroup extends FrameLayout {
    protected final String TAG = this.getClass().getSimpleName();
    protected Context mContext;
    protected Unbinder unbinder;
    private boolean isInit = false;
    protected AttributeSet attrs;
    private AppCompatActivity activity;

    public BaseCustomViewGroup(Context context) {
        super(context);
        initConfig(context, null);
    }

    public BaseCustomViewGroup(Context context, AttributeSet attrs) {
        super(context, attrs);
        initConfig(context, attrs);
    }

    public BaseCustomViewGroup(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initConfig(context, attrs);

    }

    private void initConfig(Context context, AttributeSet attributeSet) {
        if (!isInit) {
            attrs = attributeSet;
            mContext = context;
            View inflate = LayoutInflater.from(mContext).inflate(getLayoutID(), null);
            unbinder = ButterKnife.bind(this, inflate);
            addView(inflate);
            init(context,attributeSet);
            isInit = true;


        }
    }

    protected AttributeSet getAttrs() {
        return attrs;
    }

    protected abstract void init(Context context, AttributeSet attributeSet);


    protected abstract int getLayoutID();


}
